/* CreditsView.cpp
 * Credits: myself, graphics ripper, music composers
 *
 * Last Modified: 16.01.2014
 * Author: Guilherme S.G.
 *
 * TODO:
 */
#include "CreditsView.h"
#include "Game.h"

CreditsView::CreditsView() : View()
{
    ResourceManager *resources = controller->getResources();
    
    centerX = controller->getScreenWidth()/2;
    centerY = controller->getScreenHeight()/2;
    
    background = resources->loadImage("assets/backgrounds/credits-bg.jpg", "credits-bg");
    font = resources->loadFont("assets/fonts/njnaruto.ttf", 24, 0, "njnaruto-24");
    
    //Credits
    credits.push_back(std::pair<std::string,std::string>("Game Designer & Programmer", "Guilherme Gibertoni"));
    credits.push_back(std::pair<std::string,std::string>("Music", "Yasuharu Takanashi"));
    credits.push_back(std::pair<std::string,std::string>("Voice and AudioFX", "extracted from the anime"));
    credits.push_back(std::pair<std::string,std::string>("Game Graphics", "ripped by Naruto[NU]"));
    credits.push_back(std::pair<std::string,std::string>("Backgrounds", "freely available at wallbase.cc"));
    
    //Sprites
    ALLEGRO_BITMAP *narutoIMG = controller->getResources()->loadImage("assets/characters/naruto-sheet.png", "naruto-sheet");
    naruto = new Sprite("naruto-stance");
    naruto->setFlag(ROLLING);
    naruto->setImage(narutoIMG);
    naruto->setParameters(8, 1, 0, 2, -1);
    naruto->setPosition(centerX-65, controller->getScreenHeight()-60);
    naruto->clip(1, 3, 29, 44);
    
    /*ALLEGRO_BITMAP *narutoIMG = controller->getResources()->loadImage("assets/characters/naruto-sheet.png", "naruto-sheet");
    naruto = new Sprite("naruto-chakra");
    naruto->setFlag(ROLLING);
    naruto->setImage(narutoIMG);
    naruto->setParameters(6, 1, 0, 7, -1);
    naruto->setPosition(centerX+65, controller->getScreenHeight()-60);
    naruto->clip(0, 40, 1, 8, 42, 54);
    
    ALLEGRO_BITMAP *narutoIMG = controller->getResources()->loadImage("assets/characters/naruto-sheet.png", "naruto-sheet");
    naruto = new Sprite("naruto-rasengan");
    naruto->setFlag(ROLLING);
    naruto->setImage(narutoIMG);
    naruto->setParameters(6, 1, 0, 12, -1);
    naruto->setPosition(centerX+65, controller->getScreenHeight()-60);
    naruto->clip(0, 90, 1, 13, 75, 67);*/
    
    ALLEGRO_BITMAP *sasukeIMG = controller->getResources()->loadImage("assets/characters/sasuke-sheet.png", "sasuke-sheet");
    sasuke = new Sprite("sasuke-stance");
    sasuke->setFlag(ROLLING);
    sasuke->setAnimationFlag(ALLEGRO_FLIP_HORIZONTAL);
    sasuke->setImage(sasukeIMG);
    sasuke->setParameters(6, 1, 0, 3, -1);
    sasuke->setPosition(centerX+65, controller->getScreenHeight()-60);
    sasuke->clip(0, 0, 1, 4, 28, 44);
    
    /*sasuke = new Sprite("sasuke-chakra");
    sasuke->setFlag(ROLLING);
    sasuke->setImage(sasukeIMG);
    sasuke->setParameters(5, 1, 0, 5, -1);
    sasuke->setPosition(centerX+65, controller->getScreenHeight()-60);
    sasuke->clip(0, 43, 1, 6, 40, 58);
    
    sasuke = new Sprite("sasuke-gokakyu");
    sasuke->setFlag(ROLLING);
    sasuke->setImage(sasukeIMG);
    sasuke->setParameters(6, 1, 0, 13, -1);
    sasuke->setPosition(centerX+65, controller->getScreenHeight()-60);
    sasuke->clip(0, 113, 2, 10, 101, 40);*/
}

CreditsView::~CreditsView()
{
    
}

void CreditsView::handleEvents(ALLEGRO_EVENT *event)
{
    if(event->type == ALLEGRO_EVENT_KEY_UP)
    {
        switch (event->keyboard.keycode)
        {
            case ALLEGRO_KEY_ESCAPE:
                controller->goToPreviousView();
                break;
        }
    }
}

void CreditsView::update()
{
    naruto->update();
    sasuke->update();
    //sasuke->printParam();
}

void CreditsView::render()
{
    std::vector<std::pair<std::string,std::string> >::iterator iter;
    int i;
    
    al_draw_bitmap(background, 0, 0, 0);
    
    for(iter = credits.begin(), i = 0; iter != credits.end(); iter++, i++)
    {
        int y = 70 + i*70;
        
        al_draw_text(font, al_map_rgb(0, 0, 0), centerX-2, y-2, ALLEGRO_ALIGN_CENTRE, iter->first.c_str());
        al_draw_text(font, al_map_rgb(0, 0, 0), centerX+2, y+2, ALLEGRO_ALIGN_CENTRE, iter->first.c_str());
        al_draw_text(font, al_map_rgb(255, 128, 0), centerX, y, ALLEGRO_ALIGN_CENTRE, iter->first.c_str());
        
        al_draw_text(font, al_map_rgb(0, 0, 0), centerX-2, y+23, ALLEGRO_ALIGN_CENTRE, iter->second.c_str());
        al_draw_text(font, al_map_rgb(0, 0, 0), centerX+2, y+27, ALLEGRO_ALIGN_CENTRE, iter->second.c_str());
        al_draw_text(font, al_map_rgb(255, 255, 255), centerX, y+25, ALLEGRO_ALIGN_CENTRE, iter->second.c_str());
    }
    
    naruto->animate();
    sasuke->animate();
}
